<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="月份" prop="leaseMonth">
        <el-input
          v-model="queryParams.leaseMonth"
          placeholder="请输入月份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="leaseDate">
        <el-input
          v-model="queryParams.leaseDate"
          placeholder="请输入日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员名称" prop="salesmanName">
        <el-input
          v-model="queryParams.salesmanName"
          placeholder="请输入业务员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户信息来源" prop="customerSource">
        <el-input
          v-model="queryParams.customerSource"
          placeholder="请输入客户信息来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目地区域" prop="projectArea">
        <el-input
          v-model="queryParams.projectArea"
          placeholder="请输入项目地区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入收货地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货人姓名" prop="consigneeName">
        <el-input
          v-model="queryParams.consigneeName"
          placeholder="请输入收货人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货人电话" prop="consigneeTel">
        <el-input
          v-model="queryParams.consigneeTel"
          placeholder="请输入收货人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务所属公司" prop="businessCompany">
        <el-input
          v-model="queryParams.businessCompany"
          placeholder="请输入业务所属公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货仓库名称" prop="deliveryWarehouseName">
        <el-input
          v-model="queryParams.deliveryWarehouseName"
          placeholder="请输入发货仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="已收金额" prop="receivedAccount">
        <el-input
          v-model="queryParams.receivedAccount"
          placeholder="请输入已收金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日租金合计" prop="totalDailyRent">
        <el-input
          v-model="queryParams.totalDailyRent"
          placeholder="请输入日租金合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="未收金额" prop="uncollectedAmount">
        <el-input
          v-model="queryParams.uncollectedAmount"
          placeholder="请输入未收金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单id" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="quantity">
        <el-input
          v-model="queryParams.quantity"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日租金" prop="dailyRent">
        <el-input
          v-model="queryParams.dailyRent"
          placeholder="请输入日租金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运费" prop="outLogisticsExpenses">
        <el-input
          v-model="queryParams.outLogisticsExpenses"
          placeholder="请输入运费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:salesFinancialStatistics:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:salesFinancialStatistics:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:salesFinancialStatistics:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:salesFinancialStatistics:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="salesFinancialStatisticsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="月份" align="center" prop="leaseMonth" />
      <el-table-column label="日期" align="center" prop="leaseDate" />
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="业务员名称" align="center" prop="salesmanName" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="客户信息来源" align="center" prop="customerSource" />
      <el-table-column label="项目地区域" align="center" prop="projectArea" />
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="收货地址" align="center" prop="address" />
      <el-table-column label="收货人姓名" align="center" prop="consigneeName" />
      <el-table-column label="收货人电话" align="center" prop="consigneeTel" />
      <el-table-column label="业务所属公司" align="center" prop="businessCompany" />
      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="发货仓库名称" align="center" prop="deliveryWarehouseName" />
      <el-table-column label="已收金额" align="center" prop="receivedAccount" />
      <el-table-column label="日租金合计" align="center" prop="totalDailyRent" />
      <el-table-column label="未收金额" align="center" prop="uncollectedAmount" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" />
      <el-table-column label="订单id" align="center" prop="orderId" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column label="数量" align="center" prop="quantity" />
      <el-table-column label="日租金" align="center" prop="dailyRent" />
      <el-table-column label="运费" align="center" prop="outLogisticsExpenses" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:salesFinancialStatistics:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:salesFinancialStatistics:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改销售订单统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="月份" prop="leaseMonth">
          <el-input v-model="form.leaseMonth" placeholder="请输入月份" />
        </el-form-item>
        <el-form-item label="日期" prop="leaseDate">
          <el-input v-model="form.leaseDate" placeholder="请输入日期" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="业务员名称" prop="salesmanName">
          <el-input v-model="form.salesmanName" placeholder="请输入业务员名称" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="客户信息来源" prop="customerSource">
          <el-input v-model="form.customerSource" placeholder="请输入客户信息来源" />
        </el-form-item>
        <el-form-item label="项目地区域" prop="projectArea">
          <el-input v-model="form.projectArea" placeholder="请输入项目地区域" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="收货地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入收货地址" />
        </el-form-item>
        <el-form-item label="收货人姓名" prop="consigneeName">
          <el-input v-model="form.consigneeName" placeholder="请输入收货人姓名" />
        </el-form-item>
        <el-form-item label="收货人电话" prop="consigneeTel">
          <el-input v-model="form.consigneeTel" placeholder="请输入收货人电话" />
        </el-form-item>
        <el-form-item label="业务所属公司" prop="businessCompany">
          <el-input v-model="form.businessCompany" placeholder="请输入业务所属公司" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="发货仓库名称" prop="deliveryWarehouseName">
          <el-input v-model="form.deliveryWarehouseName" placeholder="请输入发货仓库名称" />
        </el-form-item>
        <el-form-item label="已收金额" prop="receivedAccount">
          <el-input v-model="form.receivedAccount" placeholder="请输入已收金额" />
        </el-form-item>
        <el-form-item label="日租金合计" prop="totalDailyRent">
          <el-input v-model="form.totalDailyRent" placeholder="请输入日租金合计" />
        </el-form-item>
        <el-form-item label="未收金额" prop="uncollectedAmount">
          <el-input v-model="form.uncollectedAmount" placeholder="请输入未收金额" />
        </el-form-item>
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="日租金" prop="dailyRent">
          <el-input v-model="form.dailyRent" placeholder="请输入日租金" />
        </el-form-item>
        <el-form-item label="运费" prop="outLogisticsExpenses">
          <el-input v-model="form.outLogisticsExpenses" placeholder="请输入运费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSalesFinancialStatistics, getSalesFinancialStatistics, delSalesFinancialStatistics, addSalesFinancialStatistics, updateSalesFinancialStatistics } from "@/api/module/salesFinancialStatistics";

export default {
  name: "SalesFinancialStatistics",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单统计表格数据
      salesFinancialStatisticsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        leaseMonth: null,
        leaseDate: null,
        orderNo: null,
        salesmanName: null,
        projectName: null,
        customerSource: null,
        projectArea: null,
        customerName: null,
        address: null,
        consigneeName: null,
        consigneeTel: null,
        businessCompany: null,
        province: null,
        city: null,
        deliveryWarehouseName: null,
        receivedAccount: null,
        totalDailyRent: null,
        uncollectedAmount: null,
        orderStatus: null,
        orderId: null,
        model: null,
        quantity: null,
        dailyRent: null,
        outLogisticsExpenses: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        leaseMonth: [
          { required: true, message: "月份不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销售订单统计列表 */
    getList() {
      this.loading = true;
      listSalesFinancialStatistics(this.queryParams).then(response => {
        this.salesFinancialStatisticsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        leaseMonth: null,
        leaseDate: null,
        orderNo: null,
        salesmanName: null,
        projectName: null,
        customerSource: null,
        projectArea: null,
        customerName: null,
        address: null,
        consigneeName: null,
        consigneeTel: null,
        businessCompany: null,
        province: null,
        city: null,
        deliveryWarehouseName: null,
        receivedAccount: null,
        totalDailyRent: null,
        uncollectedAmount: null,
        orderStatus: "0",
        orderId: null,
        model: null,
        quantity: null,
        dailyRent: null,
        outLogisticsExpenses: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.leaseMonth)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加销售订单统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const leaseMonth = row.leaseMonth || this.ids
      getSalesFinancialStatistics(leaseMonth).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改销售订单统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.leaseMonth != null) {
            updateSalesFinancialStatistics(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSalesFinancialStatistics(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const leaseMonths = row.leaseMonth || this.ids;
      this.$modal.confirm('是否确认删除销售订单统计编号为"' + leaseMonths + '"的数据项？').then(function() {
        return delSalesFinancialStatistics(leaseMonths);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/salesFinancialStatistics/export', {
        ...this.queryParams
      }, `salesFinancialStatistics_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
